<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\JsonRpc;

use App\Repository\GoodsCommentRepository;
use Hyperf\RpcServer\Annotation\RpcService;
use App\JsonRpc\Interfaces\GoodsCommentServiceInterface;

/**
 * @RpcService(name="Orders::GoodsCommentService", protocol="jsonrpc", server="jsonrpc")
 */
class GoodsCommentService extends BaseService implements GoodsCommentServiceInterface
{
    public function init()
    {
        $this->repository = GoodsCommentRepository::getInstance();
    }


    /**
     * Notes: 商品评论列表
     * Author: Bruce.z
     * DateTime: 2022/8/19 14:20
     * @param array $condition
     * @param array $field
     * @param int $page
     * @param int $size
     * @return array
     */
    public function list(array $condition, array $field, int $page, int $size): array
    {
        if(!empty($condition['oid']) ){
            $oid = $condition['oid'];
            unset($condition['oid']);
            $condition[] = ['oid','like','%'.trim($oid).'%'];
        }
        return $this->repository->list($condition, $field, $page, $size);
    }

    public function listPc(array $condition, array $field, int $page, int $size): array
    {
        if(!empty($condition['goods_mark']) ){
            $condition['goods_mark'] -= 1;
        }

        $condition['status'] = 1; //已审核
        return $this->repository->list($condition, $field, $page, $size);
    }

    /**
     * Notes: 评论数量
     * Author: Bruce.z
     * DateTime: 2022/9/27 15:09
     * @param int $goods_id
     * @return mixed
     */
    public function goodsCommentRate(int $goods_id)
    {
        return $this->repository->goodsCommentRate($goods_id);
    }

}
